package net.huashitong.common.dao;

import com.sirdc.modules.core.dao.GenericQuery;
import com.sirdc.modules.core.dao.StringDao;
import com.sirdc.modules.utils.StringUtils;
import net.huashitong.common.entity.WeekDocument;
import net.huashitong.common.filter.WeekDocumentFilter;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ling
 * Date: 2019/11/8
 * Time: 16:36
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Repository
public class WeekDocumentDao extends StringDao<WeekDocument> {
    public List<WeekDocument> queryFilter(WeekDocumentFilter filter) {
        GenericQuery query = createQuery("obj");
        if (StringUtils.isNotBlank(filter.getTitle())) {
            query.append(" and title =:title").setParam("title",StringUtils.getLikewords(filter.getTitle()) );
        }
        if (StringUtils.isNotBlank(filter.getPeriod())){
            query.append(" and period =:period").setParam("period",filter.getPeriod() );
        }
        if (StringUtils.isNotBlank(filter.getCategory())){
            query.append(" and category =:category").setParam("category",filter.getCategory() );
        }
        if (StringUtils.isNotBlank(filter.getWeekDocName())){
            query.append(" and weekDocName =:weekDocName").setParam("weekDocName",StringUtils.getLikewords(filter.getWeekDocName()) );
        }
        if (StringUtils.isNotBlank(filter.getState())){
            query.append(" and state= :state").setParam("state",filter.getState() );
        }
        return query.listResult(filter);
    }
}
